#!/usr/bin/python
#coding:utf8
'''
Factory Method
'''

# 以手机、平板生产为例
class Phone:
    def getPrcie(self):
        return self.prcie
    def getName(self):
        return self.name

class VivoPhone(Phone):
    def __init__(self,name,price):
        self.name = name
        self.prcie = price

class Factory:
    def makeProduct(self):
        pass

class VivoFactory(Factory):
    def makeProduct(self, name, price):
        return VivoPhone(name, price)

if __name__ == "__main__":
    phone1 = VivoFactory().makeProduct("Vivo-X9", 2000)
    phone2 = VivoFactory().makeProduct("Vivo-X10", 2500)
    print(f"{phone1.getName()}的定价为{phone1.getPrcie()}")
    print(f"{phone2.getName()}的定价为{phone2.getPrcie()}")

#%%
# 抽象工厂模式
class Phone:
    def getPrcie(self):
        return self.prcie
    def getName(self):
        return self.name

class VivoPhone(Phone):
    def __init__(self,name,price):
        self.name = name
        self.prcie = price

class Headset:
    pass
class VivoHeadset(Headset):
    def introduce(self):
        print("Vivo Headset")

class Factory:
    def makeProduct(self):
        pass

class VivoFactory(Factory):
    def makeProduct(self, name, price):
        return VivoPhone(name, price)
    def makeHeadset(self):
        return VivoHeadset()

if __name__ == "__main__":
    phone = VivoFactory().makeProduct("Vivo-X9", 2000)
    headset = VivoFactory().makeHeadset()
    print(f"{phone.getName()}的定价为{phone.getPrcie()}")
    headset.introduce()
